var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var webpack = require('webpack');

module.exports = {
    cache: true,
    entry: {
        main: './js/main.js'
    },
    output: {
        path: path.resolve(__dirname, 'build'),
        filename: '[name]-[hash].bundle.js'
    },
    debug: true,
    devtool: '#inline-source-map',
    module: {
        loaders: [{
            test: /\.vue$/,
            loader: 'babel?{"presets":["es2015"],"cacheDirectory": true}!vue',
            exclude: /node_modules/
        }, {
            test: /\.js$/,
            loader: 'babel?{"presets":["es2015"],"cacheDirectory": true}',
            exclude: /node_modules/
        }, {
            test: /\.css$/,
            loader: ExtractTextPlugin.extract('css?sourceMap')
        }, {
            test: /\.less$/,
            loader: ExtractTextPlugin.extract('css?sourceMap!less?sourceMap')
        }, {
            test: /\.(png|jpg)$/,
            loader: 'url?limit=15000'
        }, {
            test: /\.(woff|woff2|svg|eot|ttf|svg)$/,
            loader: 'url?limit=15000'
        },{
            test: /\.(html)$/,
            loader: 'html'
        }]
    },
    resolve: {
        root: [
            path.resolve(__dirname),
            path.resolve(__dirname, 'js')
        ],
        extensions: [
            '',
            '.js',
            '.vue',
            '.css',
            '.less'
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: 'index.html',
            inject: 'body',
            template: 'index.html',
            favicon: 'img/favicon.ico',
            hash: false
        }),
        new HtmlWebpackPlugin({
            filename: 'sub.html',
            inject: 'body',
            template: 'sub.html',
            favicon: 'img/favicon.ico',
            hash: true
        }),
        new ExtractTextPlugin('[name]-[hash].bundle.css'),
        new webpack.DllReferencePlugin({
           context: path.join(__dirname),
           manifest: require("./vendor-manifest.json")
       })
    ]
};
